package com.helper;

import org.luaj.vm2.ast.Str;

public class Debug {


    public static void log(String params){
        String className = Thread.currentThread().getStackTrace()[1].getClassName();//调用的类名
        int lineNumber = Thread.currentThread().getStackTrace()[0].getLineNumber();//调用的行数
        System.out.println(getPreStatu()+params);
    }

    public static String getPreStatu(){
//        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
//        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
//        if (stackTraceElements.length > 3) {
//            System.out.println("test2方法输出0---调用类：" + stackTraceElements[0].getClassName() + "，调用方法：" + stackTraceElements[0].getMethodName() + "，调用行数：" + stackTraceElements[0].getLineNumber());
//            System.out.println("test2方法输出1---调用类：" + stackTraceElements[1].getClassName() + "，调用方法：" + stackTraceElements[1].getMethodName() + "，调用行数：" + stackTraceElements[1].getLineNumber());
//            System.out.println("test2方法输出2---调用类：" + stackTraceElements[2].getClassName() + "，调用方法：" + stackTraceElements[2].getMethodName() + "，调用行数：" + stackTraceElements[2].getLineNumber());
//            System.out.println("test2方法输出3---调用类：" + stackTraceElements[3].getClassName() + "，调用方法：" + stackTraceElements[3].getMethodName() + "，调用行数：" + stackTraceElements[3].getLineNumber());
//        }
        String className = Thread.currentThread().getStackTrace()[3].getClassName();//调用的类名
        int lineNumber = Thread.currentThread().getStackTrace()[3].getLineNumber();//调用的行数
        String[] arr = className.split("\\.");
        return "("+arr[arr.length - 1]+","+lineNumber+"): ";
    }
    public static void log(String... params){
        String ps = "";
        for (String key:params
             ) {
            ps+=("("+key+"),");
        }
        System.out.println(getPreStatu()+ps.substring(0,ps.length()-1));
    }
}
